<template>
	<view class="u-demo">
		
			<view v-for="(item,index) in messageListData" :key="index" >
				<uni-transition :duration="item.duration" :mode-class="'slide-bottom'"  :show="true" >
					<view class="item flex" style="margin-left: 20rpx;margin-right: 20rpx; background-color: #FFFFFF;margin-top: 20rpx;padding: 20rpx;margin-bottom: 20rpx;border-radius: 10rpx; ">
						<view class="" style="flex: 1;display:flex;align-items: center;">
							<image class="image" src="../static/xiaoxi-min.png" style=""></image>
						</view>
						<!-- uni-app长时间按事件  -->
						<view class="flex-1" style="flex: 9;" @longpress="logoTime(item.send_content)">
							 <view class="flex Jbetween" style="padding-left: 20rpx;">
								  <text class="title f30 fontWeight" >通知</text>
								  <text class="f20 c999">{{item.createtime}}</text>
							 </view>
							 <view style="margin-top: 20rpx;margin-left: 20rpx;" class="f24 c666 txt">
								 <view class="" style="margin-bottom: 20rpx;color: #1c7108;font-weight: bold;">{{item.sender}}</view>
								 <view class="" style="word-break: break-all;word-wrap: break-word;">{{item.send_content}}</view>
							 </view>
						</view>
					</view>
				</uni-transition>
		   </view>
	   
		<view style="margin-top: 50rpx;margin-bottom: 100rpx;">
			<u-loadmore
			  :status="status" 
			  :loading-text="loadingText" 
			  :loadmore-text="loadmoreText" 
			  :nomore-text="nomoreText" 
				 />
		</view>
	</view>
</template>

<script>
	import util from  '../../../utils/util.js'
	export default {
		data() {
			return {
				status: 'nomore',
				loadingText: '努力加载中',
				loadmoreText: '轻轻上拉',
				nomoreText: '实在没有了',
				messageListData:[],//消息列表数据
				user_type:'',//用户类型
				receiver:''//接受者姓名
			}
		},
		onLoad() {
			this.status='loading'
			// 获取用户信息
			let userInfo=uni.getStorageSync('userInfo')
			this.user_type=userInfo.user_type
			if(userInfo){
				if(userInfo.user_type==="自然人"){
					this.receiver=userInfo[0].name
				}else if(userInfo.user_type==="法人"){
					this.receiver=userInfo[0].contacts
				}else {
					this.receiver=userInfo[0].name
				}
			}
			console.log('获取类型人',this.user_type)
			// 获取消息列表
			this.getMessageListData()
		},     
		methods: {
			// 列表长时按事件 
			logoTime:function(data){
				this.$.toast('开始了')
				 uni.setClipboardData({//uni-app长按复制方法
					data: data, //自定义
					success: function (res) {
						console.log('success',res);
					}
				});
			},
			// 获取消息列表
			getMessageListData:function(){
				var _self=this
				this.$.tipLoading('加载中')
				uni.request({
				    method: 'POST',
				    url: 'https://jizhang.xqyu.cn/index.php/api/index/get_message',
				    dataType: 'json',
				    header: {
				        'content-type': 'application/x-www-form-urlencoded'
				    },
				    data: {
				        user_type: _self.user_type,
						  receiver:_self.receiver
				    },
				    success: function (res) {
						 _self.status='nomore'
						_self.$.hideLoading()// 数据加载完成，隐藏弹窗
					   if (res.data.code == 1) {
							
							let duration=1000
							for(var i=0;i<res.data.data.length;i++){
								duration+=200
								res.data.data[i].duration=duration
							}
							let data =res.data.data
							data.forEach(item=>{
								let time=util.timestampToTime(item.createtime)
								item.createtime=time
							})
							_self.messageListData=res.data.data
							console.log('转换后的',_self.messageListData)
					   }
				    }
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.image{
		width: 80rpx;
		height: 80rpx;
	}
</style>